package com.punai.config.sqlitedomain.bo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.punai.common.utils.PnDictUtil;
import com.punai.config.sqlitedomain.ConfigIndicatorItem;
import com.punai.config.sqlitedomain.StructureLinkItem;
import io.netty.util.internal.StringUtil;


import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class StructureLinkItemBo extends StructureLinkItem {

    private String itemCode;
    private String itemName;
    private String itemUnit;

    private BigDecimal squareMeterIndex;
    private BigDecimal unitConsumption;
    private String calculationCodeName;

    private List<StructureLinkItemBo> children = new ArrayList<>();

    private BigDecimal avgValue;

    public BigDecimal getAvgValue() {
      return avgValue;
    }

    public void setAvgValue(BigDecimal avgValue) {
      this.avgValue = avgValue;
    }

    private String valueRange;


    public String getValueRange() {
      return valueRange;
    }

    public void setValueRange(String valueRange) {
      this.valueRange = valueRange;
    }

    public String getItemCode() {
        return itemCode;
    }

    public void setItemCode(String itemCode) {
        this.itemCode = itemCode;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public String getItemUnit() {
        return itemUnit;
    }

    public void setItemUnit(String itemUnit) {
        this.itemUnit = itemUnit;
    }

    public BigDecimal getSquareMeterIndex() {
        return squareMeterIndex;
    }

    public void setSquareMeterIndex(BigDecimal squareMeterIndex) {
        this.squareMeterIndex = squareMeterIndex;
    }

    public BigDecimal getUnitConsumption() {
        return unitConsumption;
    }

    public void setUnitConsumption(BigDecimal unitConsumption) {
        this.unitConsumption = unitConsumption;
    }

    public String getCalculationCodeName() {
        return calculationCodeName;
    }

    public void setCalculationCodeName(String calculationCodeName) {
        this.calculationCodeName = calculationCodeName;
    }

    public List<StructureLinkItemBo> getChildren() {
        return children;
    }

    public void setChildren(List<StructureLinkItemBo> children) {
        this.children = children;
    }

    public static StructureLinkItemBo conversion(StructureLinkItem link, ConfigIndicatorItem item){
        StructureLinkItemBo bo = new StructureLinkItemBo();
        BeanUtil.copyProperties(link,bo);
        bo.setItemCode(item.getCode());
        bo.setItemName(item.getName());
        bo.setItemUnit(item.getUnit());
        String calculationCode = bo.getCalculationCode();
        bo.setCalculationCodeName(StringUtil.isNullOrEmpty(calculationCode) ?null: PnDictUtil.getDictionary(calculationCode).getName());
        return bo;
    }

}
